<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	groupCd	= Request("findGroupCd")
	item		= Request("findItem")

	SQLTitle = "-- ■■■■ 기초코드 정보 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If groupCd <> "" Then 
		addSql = " A.groupCd='" & groupCd & "' "
	End If 
	If item <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " (A.itemNm LIKE '%" & item & "%' OR A.itemCd LIKE '%" & item & "%') "
	End If 

	If addSql <> "" Then 
		addSql = " WHERE " & addSql 
	End If 

	SQL = "SELECT A.groupCd, A.groupNm, A.itemCd, A.itemNm, A.itemSeq, A.flag, B.restQty " & _
			"	FROM tblComCode A LEFT JOIN (SELECT srcCd, (SUM(input) - SUM(output)) restQty FROM tblSrcInOut WHERE flag='Y' GROUP BY srcCd) B ON A.itemCd=B.srcCd " & addSql & _
			"	ORDER BY A.groupCd, A.flag DESC, A.itemSeq" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<ComCodes>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			restQty = "&nbsp;"
			If rs("groupCd") = "0002" Then 
				restQty = rs("restQty")
				If ISNULL(restQty) = true Then
					restQty = "&nbsp;"
				End If 
			End If 
			Response.write "	<ComCode>" & vbcrlf
				Call mkXMLNode("groupCd", rs("groupCd"), 2)
				Call mkXMLNode("groupNm", rs("groupNm"), 2)
				Call mkXMLNode("itemCd", rs("itemCd"), 2)
				Call mkXMLNode("itemNm", rs("itemNm"), 2)
				Call mkXMLNode("restQty", restQty, 2)
				Call mkXMLNode("itemSeq", rs("itemSeq"), 2)
				Call mkXMLNode("flag", Rs("flag"), 2)
			Response.write "	</ComCode>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</ComCodes>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>